# Copyright 2014-2025 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0

# Configure Vulkan-Docs Antora tree with generated files and transformed
# markup files.
# Branch selection will come later. For now it is the current branch.

RMRF = rm -rf

JSAPIMAP = ./gen/apimap.cjs
XREFMAPS = $(PYXREFMAP) $(JSXREFMAP)
PYXREFMAP = antora/spec/xrefMap.py
JSXREFMAP = antora/spec/xrefMap.cjs
JSPAGEMAP = antora/spec/modules/ROOT/partials/gen/pageMap.cjs

setup: setup_spec setup_features

# Rewrite Vulkan spec sources and images into the spec/module/ROOT
# component
# Page headers are added to pull in required attributes
# Also creates apimap.cjs, pageMap.cjs, and xrefMap.cjs for use by the
# Antora version of the spec macros. They are copied into the Antora
# playbook repository prior to building the site.
setup_spec: xrefmaps spec_pages

# Generate the (anchor name -> [ chapter anchor, anchor title ]) maps
# (xrefMap.py / xrefMap.cjs), and the API information (jsapi /
# apimap.cjs) from spec HTML
xrefmaps:
	$(RMRF) gen
	./makeSpec QUIET=@ -clean -spec all -genpath gen generated jsapi html
	scripts/map_html_anchors.py gen/out/html/vkspec.html \
	    -pyfile $(PYXREFMAP) -jsfile $(JSXREFMAP)

# Rewrite spec sources
# Individual files must be specified last
spec_pages:
	scripts/antora-prep.py \
	    -root . \
	    -component $(shell realpath antora/spec/modules/ROOT) \
	    -xrefpath antora/spec \
	    -pageHeaders antora/pageHeaders-spec.adoc \
	    -jspagemap $(JSPAGEMAP) \
	    -pypagemap $(PYPAGEMAP) \
	    ./config/attribs.adoc \
	    ./config/copyright-ccby.adoc \
	    ./config/copyright-spec.adoc \
	    ./images/*.svg \
	    `find ./gen ./chapters ./appendices -name '[A-Za-z]*.adoc' | grep -v /vulkanscdeviations.adoc` \
	    $(JSAPIMAP)

# Rewrite feature descriptions into the features/module/features component.
# No additional pageHeaders required.
setup_features: features_nav
	scripts/antora-prep.py \
	    -root . \
	    -component $(shell realpath antora/features/modules/features) \
	    -xrefpath antora/features \
	    `find ./images/proposals -type f` \
	    `find ./proposals -name '[A-Za-z]*.adoc'`

# Construct the features nav.adoc from the current list of
# features, so it remains up to date.
# This could be merged into antora-prep.py but is very specific
# to the features module, so that is pointless.
# We no longer include the proposal template.
# To restore it, add
#   -templatepath proposals/template.adoc
# and uncomment that option in the script.
features_nav:
	scripts/antora-nav-features.py \
	    -root . \
	    -component $(shell realpath antora/features/modules/features) \
	    -roadmappath proposals/Roadmap.adoc \
	    `find ./proposals -name 'VK_*.adoc'`

# Files generated by 'setup' target
# Omit antora/features/modules/features/nav.adoc which is generated, but
# also checked in.
ANTORA_GENERATED = \
	antora/spec/modules/ROOT/images \
	antora/spec/modules/ROOT/pages/appendices \
	antora/spec/modules/ROOT/pages/chapters \
	antora/spec/modules/ROOT/pages/partials \
	antora/spec/modules/ROOT/pages/gen \
	antora/spec/modules/ROOT/partials \
	antora/features/modules/features/pages/proposals \
	antora/features/modules/features/partials \
	antora/features/modules/features/images \
	$(JSXREFMAP) \
	$(PYXREFMAP)

clean:
	$(RMRF) $(ANTORA_GENERATED)
